
<html>
<style>
    img{
        width: 120px;
        height: 120px;
    }
</style>
<body>
<h1>图片上传</h1>

<form method="post" action="upload.php" enctype="multipart/form-data">
    <input type="file" name="file" id="file" multiple="multiple">
    <img src="" id="showImg">
    <input type="submit" value="提交">

</form>
</body>
<script>
    var fileObj = document.getElementById('file');
    function showImg() {

        var files = fileObj['files'];
        var URL = window.URL || window.webkitURL;
        var imgURL = URL.createObjectURL(files[0]);
        document.getElementById('showImg').src = imgURL;
    }
    onload = function(){
        console.log(fileObj);
        fileObj.onchange = showImg;
    }
</script>

</html>